package com.hotel.servlet;

import com.hotel.bean.Account;
import com.hotel.bean.Address;
import com.hotel.dao.AddressDao;
import com.hotel.util.DBOperation;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * @author KungSu.
 * @create 2021-05-13 10:09
 */
@WebServlet(value = "/AddAddressServlet")
public class AddAddressServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        Account account = (Account)request.getSession().getAttribute("curUser");
        SqlSession sqlSession = DBOperation.getSqlSession();
        //新建实体类
        AddressDao addressDao =  sqlSession.getMapper(AddressDao.class);
        Address addr = new Address();
        addr.setAccount_id(account.getAccount_id());
        addr.setAccount_address(request.getParameter("addresss"));
        System.out.println(addr);
        addressDao.addAddress(addr);
        request.getRequestDispatcher("/CommonAddressServlet?type=info").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
